﻿<!--
	This software known as 'Distrib' is under the GNU GPL v2. License
		This license can be found at: http://www.gnu.org/licenses/gpl-2.0.html

	Unless this software has been made available to you under the terms of an alternative license by
	Clint Pearson, your use of this software is dependent upon compliance with the GNU GPL v2. license.

	This software is the sole copyright of Clint Pearson
		Contact: clintkpearson@gmail.com

	This software is provided with NO WARRANTY at all, explicit or implied.

	If you wish to contact me about the software / licensing you can reach me at distribgrid@gmail.com
-->
<metro:Window x:Class="ProcessRunner.Views.ProcessHostInteractionWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:metro="http://schemas.codeplex.com/elysium"
        xmlns:mpara="http://schemas.codeplex.com/elysium/params"
        xmlns:prism="http://www.codeplex.com/prism"
        mpara:Manager.Theme="Light"
        mpara:Manager.AccentBrush="{x:Static metro:AccentBrushes.Lime}"
        mpara:Manager.ContrastBrush="White"
        Title="{Binding Title}"
        MinHeight="800" MinWidth="800" Height="800" Width="800"
        Icon="/Assets/icon.ico">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <GroupBox Header="Available Jobs">
            <ListBox IsEnabled="{Binding CanEnterInputs}" SelectedItem="{Binding SelectedJob, Mode=OneWayToSource}" x:Name="jobDefinitionsList" ItemsSource="{Binding ProcessHost.JobDefinitions}" Padding="10">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Vertical" Margin="0,5,0,5">
                            <TextBlock TextWrapping="Wrap" Text="{Binding Name}" FontSize="16" Margin="5,0,0,0" FontWeight="Bold" />
                            <TextBlock TextWrapping="Wrap" Text="{Binding Description}"
                                       FontSize="14" Margin="10,0,0,0" FontStyle="Italic" />
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </GroupBox>

        <Grid Grid.Column="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <Grid Grid.Row="0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <GroupBox Header="Inputs" Grid.Row="0">
                    <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
                        <ItemsControl Padding="10" ItemsSource="{Binding Path=SelectedItem.InputFields, ElementName=jobDefinitionsList}" IsEnabled="{Binding CanEnterInputs}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <GroupBox Header="{Binding Definition.Name}" Margin="5">
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="*" />
                                            </Grid.ColumnDefinitions>

                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="Auto" />
                                                <RowDefinition Height="Auto" />
                                            </Grid.RowDefinitions>

                                            <Label Grid.Column="0" Grid.Row="0"
                                               HorizontalAlignment="Right" VerticalAlignment="Center"
                                               Content="Value:" />

                                            <StackPanel Grid.Column="1" Grid.Row="0" Orientation="Vertical">
                                                <TextBox
                                                 HorizontalAlignment="Stretch" VerticalAlignment="Center"
                                                 Text="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}">
                                                    <TextBox.Style>
                                                        <Style TargetType="TextBox" BasedOn="{StaticResource TextBoxBaseStyle}">
                                                            <Style.Triggers>
                                                                <Trigger Property="Validation.HasError" Value="True">
                                                                    <Setter Property="ToolTip"
                                                                        Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
                                                                </Trigger>
                                                            </Style.Triggers>
                                                        </Style>
                                                    </TextBox.Style>
                                                </TextBox>
                                            </StackPanel>

                                            <GroupBox Header="Config" Grid.ColumnSpan="2" Grid.Row="1">
                                                <Grid>
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="Auto" />
                                                        <ColumnDefinition Width="*" />
                                                    </Grid.ColumnDefinitions>

                                                    <Grid.RowDefinitions>
                                                        <RowDefinition Height="Auto" />
                                                        <RowDefinition Height="Auto" />
                                                        <RowDefinition Height="Auto" />
                                                        <RowDefinition Height="Auto" />
                                                        <RowDefinition Height="Auto" />
                                                        <RowDefinition Height="Auto" />
                                                    </Grid.RowDefinitions>

                                                    <Label Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right" VerticalAlignment="Center"
                                                       Content="Display Name:" />
                                                    <Label Grid.Column="1" Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Center">
                                                        <Label.Style>
                                                            <Style TargetType="Label">
                                                                <Setter Property="Content" Value="No Display Name Set" />
                                                                <Style.Triggers>
                                                                    <DataTrigger Binding="{Binding Definition.Config.HasDisplayName}" Value="True">
                                                                        <Setter Property="Content" Value="{Binding Definition.Config.DisplayName}" />
                                                                    </DataTrigger>
                                                                </Style.Triggers>
                                                            </Style>
                                                        </Label.Style>
                                                    </Label>

                                                    <Label Grid.Column="0" Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Center"
                                                       Content="Default Value:" />
                                                    <Label Grid.Column="1" Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Center">
                                                        <Label.Style>
                                                            <Style TargetType="Label">
                                                                <Setter Property="Content" Value="No Default Value Set" />
                                                                <Style.Triggers>
                                                                    <DataTrigger Binding="{Binding Definition.Config.HasDefaultValue}" Value="True">
                                                                        <Setter Property="Content" Value="{Binding Definition.Config.DefaultValue}" />
                                                                    </DataTrigger>
                                                                </Style.Triggers>
                                                            </Style>
                                                        </Label.Style>
                                                    </Label>

                                                    <Label Grid.Column="0" Grid.Row="2" HorizontalAlignment="Right" VerticalAlignment="Center"
                                                       Content="Deferred Value Provider:" />
                                                    <Label Grid.Column="1" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Center">
                                                        <Label.Style>
                                                            <Style TargetType="Label">
                                                                <Setter Property="Content" Value="No Deferred Value Provider Set" />
                                                                <Style.Triggers>
                                                                    <DataTrigger Binding="{Binding Definition.Config.HasDeferredValueProvider}" Value="True">
                                                                        <Setter Property="Content" Value="{Binding Definition.Content.DeferredValueProvider}" />
                                                                    </DataTrigger>
                                                                </Style.Triggers>
                                                            </Style>
                                                        </Label.Style>
                                                    </Label>
                                                </Grid>
                                            </GroupBox>
                                        </Grid>
                                    </GroupBox>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </ScrollViewer>
                </GroupBox>

                <Grid Grid.Row="1" HorizontalAlignment="Stretch" Margin="10">
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Stretch">
                        <metro:ProgressRing Width="25" Height="25" Margin="10">
                            <metro:ProgressRing.Style>
                                <Style TargetType="metro:ProgressRing">
                                    <Setter Property="State" Value="Normal" />
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Path=ProcessHost.IsProcessing}" Value="True">
                                            <Setter Property="State" Value="Indeterminate" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </metro:ProgressRing.Style>
                        </metro:ProgressRing>
                        <Button IsEnabled="{Binding CanExecuteJob}" Command="{Binding ExecuteJobCommand}"
                            CommandParameter="{Binding Path=SelectedItem, ElementName=jobDefinitionsList}" Width="100" Height="Auto" Content="Execute" HorizontalAlignment="Right" VerticalAlignment="Center" />
                    </StackPanel>
                </Grid>
            </Grid>

            <GroupBox Grid.Row="1" Header="Ouputs">
                <StackPanel Orientation="Vertical">
                    <ItemsControl Padding="10" ItemsSource="{Binding Path=SelectedJob.OutputFields}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <GroupBox Header="{Binding Definition.Name}" Margin="5">
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition Width="*" />
                                        </Grid.ColumnDefinitions>

                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto" />
                                            <RowDefinition Height="Auto" />
                                        </Grid.RowDefinitions>

                                        <Label Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right" VerticalAlignment="Center"
                                           Content="Value:" />
                                        <Label Grid.Column="1" Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Center"
                                           Content="{Binding Value}" />

                                        <GroupBox Header="Config" Grid.ColumnSpan="2" Grid.Row="1">
                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="Auto" />
                                                    <ColumnDefinition Width="*" />
                                                </Grid.ColumnDefinitions>

                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="Auto" />
                                                    <RowDefinition Height="Auto" />
                                                    <RowDefinition Height="Auto" />
                                                    <RowDefinition Height="Auto" />
                                                    <RowDefinition Height="Auto" />
                                                    <RowDefinition Height="Auto" />
                                                </Grid.RowDefinitions>

                                                <Label Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right" VerticalAlignment="Center"
                                                       Content="Display Name:" />
                                                <Label Grid.Column="1" Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Center">
                                                    <Label.Style>
                                                        <Style TargetType="Label">
                                                            <Setter Property="Content" Value="No Display Name Set" />
                                                            <Style.Triggers>
                                                                <DataTrigger Binding="{Binding Definition.Config.HasDisplayName}" Value="True">
                                                                    <Setter Property="Content" Value="{Binding Definition.DisplayName}" />
                                                                </DataTrigger>
                                                            </Style.Triggers>
                                                        </Style>
                                                    </Label.Style>
                                                </Label>

                                                <Label Grid.Column="0" Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Center"
                                                       Content="Default Value:" />
                                                <Label Grid.Column="1" Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Center">
                                                    <Label.Style>
                                                        <Style TargetType="Label">
                                                            <Setter Property="Content" Value="No Default Value Set" />
                                                            <Style.Triggers>
                                                                <DataTrigger Binding="{Binding Definition.Config.HasDefaultValue}" Value="True">
                                                                    <Setter Property="Content" Value="{Binding Definition.Config.DefaultValue}" />
                                                                </DataTrigger>
                                                            </Style.Triggers>
                                                        </Style>
                                                    </Label.Style>
                                                </Label>

                                                <!--<Label Grid.Column="0" Grid.Row="2" HorizontalAlignment="Right" VerticalAlignment="Center"
                                                       Content="Deferred Value Provider:" />
                                            <Label Grid.Column="1" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Center">
                                                <Label.Style>
                                                    <Style TargetType="Label">
                                                        <Setter Property="Content" Value="No Deferred Value Provider Set" />
                                                        <Style.Triggers>
                                                            <DataTrigger Binding="{Binding Definition.Config.HasDeferredValueProvider}" Value="True">
                                                                <Setter Property="Content" Value="{Binding Definition.Content.DeferredValueProvider}" />
                                                            </DataTrigger>
                                                        </Style.Triggers>
                                                    </Style>
                                                </Label.Style>
                                            </Label>-->
                                            </Grid>
                                        </GroupBox>
                                    </Grid>
                                </GroupBox>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                    
                    <TextBlock Text="{Binding SelectedJob.ExecutionError}" FontSize="13" FontWeight="Bold" Foreground="Red" TextAlignment="Center"
                               TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Center">
                        <TextBlock.Style>
                            <Style TargetType="TextBlock">
                                <Setter Property="Visibility" Value="Collapsed" />
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding SelectedJob.HasExecutionError}" Value="True">
                                        <Setter Property="Visibility" Value="Visible" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>
                    </TextBlock>
                </StackPanel>
            </GroupBox>
        </Grid>
    </Grid>
</metro:Window>
